package com.andrew.study.file;

import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ProtocolResolver;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;

import java.io.IOException;

public class ResourceTest {

	public static void main(String[] args) throws IOException {
		DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
		resourceLoader.addProtocolResolver((location, resourceLoader1) -> {
			if (!location.startsWith("path:"))
				return null;
			String substring = location.substring(5);
			return resourceLoader1.getResource("classpath:" + substring);
		});
		Resource resource = resourceLoader.getResource("application.properties");
		System.out.println("resource is file: " + resource.isFile());
		System.out.println("resource filename is " + resource.getFilename());
		System.out.println("resource url: " + resource.getURL());
		System.out.println("resource uri: " + resource.getURI());
		System.out.println("resource file: " + resource.getFile());

		System.out.println("--------------------------");


	}

}
